<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Link extends Model
{
    //
	protected $casts = [
        'content' => 'json'
    ];
	
	public static function boot() {
        parent::boot();
        static::updated(function($model) {
			if(!isset($model->content['thumb']))
			{
				$content = json_decode($model->original['content']);
				if(isset($content->thumb) && !empty($content->thumb))
				{
					$newconent = array_add($model->content, 'thumb', $content->thumb);
					$Link = self::find($model->id);
					$Link->content = $newconent;
					$Link->save();
					// dd($Link->content);
				}
			}
			
			
			
			
            
        });
    }
}
